let H5 = document.querySelectorAll(".make_form div h5")

Name.addEventListener("blur",function(){
    let value = Name.value
    if((/^[\u4e00-\u9fa5]{1,10}$/.test(Name.value)) && value.length > 0){
        H5[0].style.display = "none"
        H5[1].style.display = "block"
        H5[1].style.color = "green"
    }else{
        H5[0].style.display = "block"
        H5[1].style.display = "none"
    }
})

phone.addEventListener("blur",function(){
    let value = phone.value;
    if((/^[1]\d{10}$/.test(value))){
        H5[2].style.display = "block"
        H5[2].style.color = "green"
        H5[3].style.display = "none"
    }else{
        H5[3].style.display = "block"
        H5[2].style.display = "none"
    }
})

idCard.addEventListener("blur",function(){
    let value = idCard.value;
    if((/^\d{17}[0-9Xx]$/.test(value))){
        H5[4].style.display = "block"
        H5[4].style.color = "green"
        H5[5].style.display = "none"
    }else{
        H5[5].style.display = "block"
        H5[4].style.display = "none"
    }
})

codebtn.addEventListener("click",function(e){
    e.preventDefault();
    ajax({
        url:"http://egg.flower.dbice.cn/api/sms",
        method:"GET",
        data:{
            phone:`${phone.value}`
        }
    }).then(res=>{
        code.value = res.data.code;
        codebtn.innerText = "以获取"
        codebtn.style.color = "gray"
        codebtn.disabled = true;
    })

})

startbtn.addEventListener("click",function(e){
    e.preventDefault();
    if(Name && phone && idCard && code){
        ajax({
            url:"http://egg.flower.dbice.cn/api/register",
            method:"POST",
            data:{
                name:`${Name.value}`,
                phone:phone.value,
                idCard:idCard.value,
                code:`${code.value}`
            }
        }).then(res=>{
            console.log(res);
            localStorage.setItem("name",Name.value)
            localStorage.setItem("phone",phone.value)
            localStorage.setItem("idCard",idCard.value)
        })

        ajax({
            url:"http://egg.flower.dbice.cn/api/login",
            method:"POST",
            data:{
                name:`${Name.value}`,
                phone:`${phone.value}`,
                idCard:`${idCard.value}`
            }
        }).then(res=>{
            console.log(res);
            localStorage.setItem("id",res.data.id)
            localStorage.setItem("token",res.data.token)
            alert("登录成功")
            location="start.html"
        })
    }else{
        alert("请输入正确的信息")
        e.preventDefault();
    }
})

mybtn.addEventListener("click",function(e){
    e.preventDefault();
    let a = null;
    a = sessionStorage.getItem("time");
    if(a){
        location.href = "end.html";
    }else{
        location.href = "null.html";
    }
})